#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>

int show(int *a, int len)
{
    for (int i = 0; i < len; i++) {
        printf("%d ", a[i]);
    }
    printf("\n");
    return 0;
}

int **generate(int numRows, int *returnSize, int **returnColumnSizes)
{
    int **result = (int **) malloc(numRows * sizeof(int *));
    int *resultCol = (int *) malloc(numRows * sizeof(int));

    for (int i = 0; i < numRows; i++) {
        result[i] = (int *) malloc((i + 1) * sizeof(int));
        result[i][0] = 1;
        result[i][i] = 1;
        for (int k = 1; k < i; k++) {
            result[i][k] = result[i - 1][k - 1] + result[i - 1][k];
        }
        resultCol[i] = i + 1;
    }

    *returnSize = numRows;
    *returnColumnSizes = resultCol;
    return result;
}

int main(int argc, char const *argv[])
{
    int numRows = 5;
    int returnSize = 0;
    int *colSize = NULL;
    int **result = generate(numRows, &returnSize, &colSize);

    for (int i = 0; i < returnSize; i++) {
        show(result[i], colSize[i]);
    }

    for (int i = 0; i < returnSize; i++) {
        free(result[i]);
    }
    free(result);
    free(colSize);

    return 0;
}